<?php
class User_InfoController extends Zend_Controller_Action
{
	private $model;
	private $auth;
	public function init(){
		$this->model = new User_Model_Info();
		$this->auth = Zend_Auth::getInstance();
		$dirfile = $this->_request->getBaseUrl() . "/application/layouts/user";
		$dirlayout = APPLICATION_PATH . "/layouts/user";
		$this->view->imgs = $dirfile . "/images";
		$this->view->headLink()->appendStylesheet($dirfile . '/css/style.css');
		$this->view->headScript()->appendFile($dirfile . '/js/jquery-1.7.2.min.js');
		$this->view->headScript()->appendFile($dirfile . '/js/dropdown.js');
		$this->view->headScript()->appendFile($dirfile . '/js/slidedown.js');
		$this->view->headScript()->appendFile($dirfile . '/js/edituser.js');
		$this->view->headScript()->appendFile($dirfile . '/js/changpass.js');
		$option = array('layoutPath'=>$dirlayout,'layout'=>'index');
		Zend_Layout::startMvc($option);
	}
	public function indexAction()
	{
		
	}
	public function vieweditAction()
	{
		$data = $this->model->getedit($this->auth->getIdentity()->id_user);
		$this->view->data = $data;
	}
	public function editAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->layout->disableLayout();
		$fullname = $this->_request->getParam('fullname');
		$address = $this->_request->getParam('address');
		$phone = $this->_request->getParam('phone');
		$email = $this->_request->getParam('email');
		$id = $this->auth->getIdentity()->id_user;
		try {
			$update = $this->model->edit($id, $fullname, $address, $email, $phone);
			echo "Edit Success";
		}catch (Zend_Db_Exception $e)
		{
			echo "Loi xu ly";
		}
	}
	public function changpassAction()
	{
		
	}
	public function changeAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->layout->disableLayout();
		$passold = $this->_request->getParam('passold');
		$passnew = $this->_request->getParam('passnew');
		$confirm = $this->_request->getParam('confirm');
		$id = $this->auth->getIdentity()->id_user;
		$pass = $this->model->getpass($id);
		if (md5($passold) != $pass['password'])
		{
			echo "Pass Old Failed";
		}
		else
		{
			if($passnew != $confirm)
			{
				echo "Incorect Pass";
			}
			else 
			{
		try
		{
			$update = $this->model->changpass($id, $passnew);
			echo "Change Pass Success";
		}catch(Zend_Db_Exception $e)
		{
			echo "Loi xu ly";
		}
			}
		}
		
	}
}